﻿using CPPEI.Coolzon.ServiceProxy.DataServiceRef;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI.DataPartLib
{
    public class DataResultLoopSpliter2 : IDataResultSpliter
    {
        public List<DataSeries> Split(DataResult dataResult, int expectedCount, int pageIndex, DataGridRowUpdateDirection direction)
        {
            List<DataSeries> segment = new List<DataSeries>();

            if (direction == DataGridRowUpdateDirection.Down)
            {
                for (int index = 0; index < expectedCount; index++)
                {
                    if (pageIndex < 0)
                    {
                        pageIndex = dataResult.DataSeries.Length - 1;
                    }
                    if (index <= dataResult.DataSeries.Length - 1)
                    {
                        segment.Add(dataResult.DataSeries[pageIndex]);
                    }
                    else
                    {
                        segment.Add(new DataSeries());
                    }
                    pageIndex--;
                }
            }
            else
            {
                for (int index = 0; index < expectedCount; index++)
                {
                    if (pageIndex >= dataResult.DataSeries.Length)
                    {
                        pageIndex = 0;
                    }
                    if (index <= dataResult.DataSeries.Length - 1)
                    {
                        segment.Add(dataResult.DataSeries[pageIndex]);
                    }
                    else
                    {
                        segment.Add(new DataSeries());
                    }
                    pageIndex++;
                }
            }
            return segment;
        }
    }
}
